<?php
/**
 * $Id: index.php v 1.00 03 july 2004 John N Exp $
 * Module: WF-Links
 * Version: v1.0.3
 * Release Date: 21 June 2005
 * Developer: John N
 * Team: WF-Projects
 * Licence: GNU
 */

include 'header.php';

$xoopsOption['template_main'] = 'wflinks_index.html';
include XOOPS_ROOT_PATH . '/header.php';

global $xoopsModuleConfig;
$mytree = new XoopsTree( $xoopsDB -> prefix( WFLINKS_CAT ), 'cid', 'pid' );

/**
 * Begin Main page Heading etc
 */
$sql = 'SELECT * FROM ' . $xoopsDB -> prefix( WFLINKS_INDEXPAGE );
$head_arr = $xoopsDB -> fetchArray( $xoopsDB -> query( $sql ) );

$catarray['imageheader'] = wfl_imageheader( $head_arr['indeximage'], $head_arr['indexheading'] );
$catarray['indexheading'] = $wfmyts -> displayTarea( $head_arr['indexheading'] );
$catarray['indexheaderalign'] = $wfmyts -> htmlSpecialCharsStrip( $head_arr['indexheaderalign'] );
$catarray['indexfooteralign'] = $wfmyts -> htmlSpecialCharsStrip( $head_arr['indexfooteralign'] );

$html = ( $head_arr['nohtml'] ) ? 0 : 1;
$smiley = ( $head_arr['nosmiley'] ) ? 0 : 1;
$xcodes = ( $head_arr['noxcodes'] ) ? 0 : 1;
$images = ( $head_arr['noimages'] ) ? 0 : 1;
$breaks = ( $head_arr['nobreak'] ) ? 1 : 0;

$catarray['indexheader'] = $wfmyts -> displayTarea( $head_arr['indexheader'], $html, $smiley, $xcodes, $images, $breaks );
$catarray['indexfooter'] = $wfmyts -> displayTarea( $head_arr['indexfooter'], $html, $smiley, $xcodes, $images, $breaks );
$catarray['letters'] = wfl_letters();
$catarray['toolbar'] = wfl_toolbar();
$xoopsTpl -> assign( 'catarray', $catarray );
/**
 * End main page Headers
 */
$count = 1;
$chcount = 0;
$countin = 0;
/**
 * Begin Main page linkload info
 */
$listings = wfl_getTotalItems();
/**
 * get total amount of categories
 */
$total_cat = wfl_totalcategory();

$sql = 'SELECT * FROM ' . $xoopsDB -> prefix( WFLINKS_CAT ) . ' WHERE pid = 0 ORDER BY weight';
$result = $xoopsDB -> query( $sql );
while ( $myrow = $xoopsDB -> fetchArray( $result ) )
{
    $countin++;
    $subtotallinkload = 0;
    $totallinkload = wfl_getTotalItems( $myrow['cid'], 0 );

    $indicator = wfl_isnewimage( $totallinkload['published'] );
    if ( checkgroups( $myrow['cid'] ) )
    {
        $title = $wfmyts -> htmlSpecialCharsStrip( $myrow['title'] );
        $summary = $wfmyts -> displayTarea( $myrow['summary'] );

        $arr = array();
        $arr = $mytree -> getFirstChild( $myrow['cid'], "title" );

        $space = $chcount = 0;
        $subcategories = "";
        foreach( $arr as $ele )
        {
            if ( true == checkgroups( $ele['groupid'] ) )
            {
                if ( $xoopsModuleConfig['subcats'] == 1 )
                {
                    $chtitle = $wfmyts -> htmlSpecialCharsStrip( $ele['title'] );
                    if ( $chcount > 5 )
                    {
                        $subcategories .= "...";
                        break;
                    } 
                    if ( $space > 0 )
                        $subcategories .= "<br />";

                    $subcategories .= "<a href='" . XOOPS_URL . "/modules/" . $xoopsModule -> getVar( 'dirname' ) . "/viewcat.php?cid=" . $ele['cid'] . "'>" . $chtitle . "</a>";
                    $space++;
                    $chcount++;
                } 
            } 
        } 
        /**
         * This code is copyright WF-Projects
         * Using this code without our permission or removing this code voids the license agreement
         */
        $_image = ( $myrow['imgurl'] ) ? urldecode( $myrow['imgurl'] ) : "";
		if ( $_image != "" && $xoopsModuleConfig['usethumbs'] )
        {
            $_thumb_image = new wfThumbsNails( $_image, $xoopsModuleConfig['catimage'], 'thumbs' );
			if ( $_thumb_image )
            {
                $_thumb_image -> setUseThumbs( 1 );
                $_thumb_image -> setImageType( 'gd2' );
                $_image = $_thumb_image -> do_thumb( $xoopsModuleConfig['shotwidth'],
                    $xoopsModuleConfig['shotheight'],
                    $xoopsModuleConfig['imagequality'],
                    $xoopsModuleConfig['updatethumbs'],
                    $xoopsModuleConfig['keepaspect'] 
                    );
            } 
        } 
        
		if ( empty( $_image ) || $_image == '' )
        {
            $imgurl = $indicator['image'];
            $_width = 33;
            $_height = 24;
        } 
        else
        {
            $imgurl = "{$xoopsModuleConfig['catimage']}/$_image";
            $_width = $xoopsModuleConfig['shotwidth'];
            $_height = $xoopsModuleConfig['shotheight'];
        } 
        /**
         * End
         */
        $xoopsTpl -> append( 'categories', array( 'image' => XOOPS_URL . "/$imgurl",
                'id' => $myrow['cid'],
                'title' => $title,
                'summary' => $summary,
                'subcategories' => $subcategories,
                'totallinks' => $totallinkload['count'],
                'width' => $_width,
                'height' => $_height,
                'count' => $count,
                'alttext' => $indicator['alttext'] ) 
            );
        $count++;
    } 
} 
switch ( $total_cat )
{
    case "1":
        $lang_thereare = _MD_WFL_THEREIS;
        break;
    default:
        $lang_thereare = _MD_WFL_THEREARE;
        break;
} 
$xoopsTpl -> assign( 'lang_thereare', sprintf( $lang_thereare, $total_cat, $listings['count'] ) );
$xoopsTpl -> assign( 'module_dir', $xoopsModule -> getVar( 'dirname' ) );
/**
 * Screenshots display
 */
if ( isset( $xoopsModuleConfig['screenshot'] ) && $xoopsModuleConfig['screenshot'] == 1 )
{
    $xoopsTpl -> assign( 'shots_dir', $xoopsModuleConfig['screenshots'] );
    $xoopsTpl -> assign( 'shotwidth', $xoopsModuleConfig['shotwidth'] );
    $xoopsTpl -> assign( 'shotheight', $xoopsModuleConfig['shotheight'] );
    $xoopsTpl -> assign( 'show_screenshot', true );
} 
include XOOPS_ROOT_PATH . '/footer.php';

?>
